import axios from 'axios';

// 获取游记列表
function getNotes(classify) {
  return new Promise((resolve, reject) => {
    axios
      .get(`/getNotes`, {
        params: { classify: classify },
      })
      .then((result) => {
        if (result.data.ok == 1) resolve(result.data.result);
        else reject();
      });
  });
}

// 搜索游记
function searchNotes(page, keyword) {
  return new Promise((resolve, reject) => {
    axios
      .get(`/searchNotes`, {
        params: { page, keyword },
      })
      .then((result) => {
        if (result.data.ok == 1) resolve(result.data);
        else reject();
      });
  });
}

// 获取推荐游记
function getRecommend() {
  return new Promise((resolve, reject) => {
    axios.get(`/getRecommend`).then((result) => {
      if (result.data.ok == 1) resolve(result.data.result);
      else reject();
    });
  });
}

// 获取游记详情
function getNoteDetail(tid) {
  return new Promise((resolve, reject) => {
    axios.get(`/getNote/${tid}`).then((result) => {
      if (result.data.ok == 1) resolve(result.data.result);
      else reject();
    });
  });
}

// 获取分享二维码
function getQrcode(url) {
  return new Promise((resolve, reject) => {
    axios.post(`/getQrcode`, `url=${url}`).then((result) => {
      if (result.data.ok == 1) resolve(result.data.result);
      else reject();
    });
  });
}

export { getNotes, searchNotes, getNoteDetail, getRecommend, getQrcode };
